//
//  KDChangePwdController.m
//  WangJingApp
//
//  Created by 魏强 on 17/11/22.
//  Copyright © 2017年 KDTech. All rights reserved.
//

#import "KDChangePwdController.h"
#import "KDLoginTool.h"
#import "KDUpdatePwdParam.h"
#import "SVProgressHUD.h"
@interface KDChangePwdController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scroll_cons_w;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *confirmBtn_to_bottom_cons;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
@property (weak, nonatomic) IBOutlet UITextField *originTf;
@property (weak, nonatomic) IBOutlet UITextField *firstPwdTf;
@property (weak, nonatomic) IBOutlet UITextField *secondTf;

@end

@implementation KDChangePwdController
#pragma mark - 懒加载区

#pragma mark - 生命周期区
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BackGroundColor;
    self.title = @"修改密码";
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.scroll_cons_w.constant = screenW;
    self.navigationController.navigationBar.hidden = NO;
    self.confirmBtn.layer.cornerRadius = 5;
    self.confirmBtn.clipsToBounds = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = YES;
    
}
#pragma mark - 板块布置区

#pragma mark - 事件点击区
- (IBAction)confirmBtnClick:(UIButton *)sender {
    if (!self.originTf.text.length) {
        [SVProgressHUD showErrorWithStatus:@"请输入原始密码" maskType:SVProgressHUDMaskTypeGradient];
        return;
    }
    if (![self.firstPwdTf.text isEqualToString:self.secondTf.text]) {
        [SVProgressHUD showErrorWithStatus:@"两次密码输入不一致！" maskType:SVProgressHUDMaskTypeGradient];
        return;
    }
    KDAccount *account = [KDAccountTool account];
    
    KDUpdatePwdParam *param = [[KDUpdatePwdParam alloc]init];
    param.userId = [NSString stringWithFormat:@"%ld",account.userId];
    param.oldPwd = self.originTf.text;
    param.newsPwd = self.secondTf.text;
    [KDLoginTool updatePwdWithParam:param success:^(KDBaseResult *responseObejct) {
        [SVProgressHUD showSuccessWithStatus:responseObejct.msg maskType:SVProgressHUDMaskTypeGradient];

        if ([responseObejct.msg isEqualToString:@"操作成功"]) {
            [self.navigationController popViewControllerAnimated:YES];
        }
    } failure:^(NSError *error) {
        KDLog(@"%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络错误！" maskType:SVProgressHUDMaskTypeGradient];

    }];
}

#pragma mark - 网络请求区

#pragma mark - 通知接收区



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
